/*
 * 快捷键对象
 * 注：此对象中的this均指向vue
 * @author: huangzong
 */
const C = require('../common/common')

const keyUpRef =  {
  
    // 增加一行
    addRow (ref) {
        this[ref.dataName].push(C.copy(ref.addRowData))
        this.setIndex(this[ref.dataName].length - 1, 1, ref)
        ref.nowIndex--
        this.nextInput(ref)
    },
    // 指针跳转
    nextInput (ref) {
    // 检测是否index
        ref.nowIndex ++
        let refs = ref.prefix + '_' + ref.nowIndex
        if (ref.nowIndex > this[ref.dataName].length * ref.indexLen) this[ref.dataName].push(C.copy(ref.addRowData))
        // 防止递归死循环
        setTimeout(() => {
            if (!this.$refs[refs] || this.$refs[refs].disabled) {
                this.nextInput(ref)
                return false
            }
            this.$refs[refs].focus()
            if (typeof this.$refs[refs].select == 'function') {
                this.$refs[refs].select() // 兼容
            }
            if (typeof this.$refs[refs].inputSelect == 'function') {
                this.$refs[refs].inputSelect() // 兼容
            }
        })
    },
    // 赋值初始ref
    makeIndex: function (row, col, ref) {
        let n = row * ref.indexLen + Number(col)
        return ref.prefix + '_' + n
    },
    // 定位指针
    setIndex: function (index, col, ref) {
        ref.nowIndex = index * ref.indexLen + Number(col)
    },





}

module.exports = keyUpRef